

var photoCtx = new ModuleContext('Photo', '照片');

var appui = new ModuleUI(photoCtx);

appui.checkEditForm = function(){
	var vConf = {};
	//
 	vConf = [
		{"name":"id","format":"Integer","tip":" 格式错误!"}
		, {"name":"albumId","format":"Integer","tip":"相册 格式错误!"}
	];
	var v = new Validator(photoCtx.EDIT_FORM_ID, vConf, true);
	var ok = v.validate();
	if(!ok){
		return false;
	}
	return true;
}

appui.setViewItem = function(dataObj, viewObj){
	viewObj.setAttribute('class','row');
	viewObj.setAttribute('id', 'XXXListItem_' + dataObj.id);
	var children = DomUtil.getChildren(viewObj);
	children[0].firstChild.value = dataObj['id'];
	children[1].innerHTML = Widget.getView(dataObj['id'], 'hidden');
	children[2].innerHTML = Widget.getView(dataObj['title'], 'text');
	//children[3].innerHTML = Widget.getView(dataObj['path'], 'text');
	UploadFileUtil.previewImg(null, dataObj['path'], children[3]);
	children[4].innerHTML = Widget.getView(dataObj['remark'], 'text');
	children[5].innerHTML = Widget.getView(dataObj['albumId'], 'select');
	children[6].innerHTML = Widget.getView(dataObj['created'], 'date');
	children[7].innerHTML = Widget.getView(dataObj['modified'], 'date');
	
	children[8].firstChild.onclick = function(){appui.editXXX(dataObj.id);};
	children[9].firstChild.onclick = function(){appui.deleteXXX(dataObj.id);};
}

EventUtil.addEvent(window, 'load', function(){
	var url_select = URL_ROOT+'/album/select.json';
	ajaxRequest(url_select, null, function(result){
		var selList = $E('PhotoEditForm')['albumId'];
		if(!selList)return;
		if(selList.tagName){
			FormUtil.bindSelectOptions(selList, result.data, 'id', 'name');
		}else{
			for(var i=0;i<selList.length;i++){
				FormUtil.bindSelectOptions(selList[i], result.data, 'id', 'name');
			}
		}
	});
});